package com.asiainfo.dacp.datastash.orm.po.state;

import com.asiainfo.dacp.jpa.annotation.ColumnPosition;
import com.asiainfo.dacp.util.DateHelper;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Parameter;

import javax.persistence.*;
import java.util.Date;

@Data
@Entity
@Table(name="dacp_datastash_unit_state")
@NoArgsConstructor
public class DataStashUnitStateLogPo {

    @Id
    @Column(name="unit_proc_id",length = 32)
    private String unitProcId;

    @Column(name="unit_code",length = 16)
    @ColumnPosition(2)
    private String unitCode;

    @Column(name="batch_no",length = 16)
    @ColumnPosition(3)
    private String batchNo;

    @Column(name="is_turnover",length = 1)
    @ColumnPosition(4)
    private String isTurnover;

    @Column(name="task_cnt")
    @ColumnPosition(5)
    private int taskCnt;

    @Column(name="create_dt")
    @ColumnPosition(6)
    private Date createDt=new Date();
    

    @Transient
    private String createDate;

    public String getCreateDate(){
        if(createDate==null || createDate.length()==0){
            createDate = DateHelper.formatDateTime(createDt);
        }
        return createDate;
    }

    public void setCreateDate(String createDate){
        this.createDate = createDate;
        createDt = DateHelper.parseDateTime(createDate);
    }


    @Column(name="start_dt")
    @ColumnPosition(7)
    private Date startDt;

    @Transient
    private String startDate;

    public String getStartDate(){
        if(startDate==null || startDate.length()==0){
            startDate = DateHelper.formatDateTime(startDt);
        }
        return startDate;
    }
    public void setStartDate(String startDate){
        this.startDate = startDate;
        startDt = DateHelper.parseDateTime(startDate);
    }


    @Column(name="complete_dt")
    @ColumnPosition(8)
    private Date completeDt;

    @Transient
    private String completeDate;

    public String getCompleteDate(){
        if(completeDate==null || completeDate.length()==0){
            completeDate = DateHelper.formatDateTime(completeDt);
        }
        return completeDate;
    }
    public void setCompleteDate(String completeDate){
        this.completeDate = completeDate;
        completeDt = DateHelper.parseDateTime(completeDate);
    }


    @Column(name="lastupd")
    @ColumnPosition(9)
    private Date lastupd=new Date();

    @Transient
    private String lastupDate;

    public String getLastupDate(){
        if(lastupDate==null || lastupDate.length()==0){
            lastupDate = DateHelper.formatDateTime(lastupd);
        }
        return createDate;
    }

    public void setLastupDate(String lastupDate){
        this.lastupDate = lastupDate;
        lastupd = DateHelper.parseDateTime(lastupDate);
    }


    @Column(length = 320)
    @ColumnPosition(10)
    private String message;

    @Column(length = 4)
    @ColumnPosition(11)
    private String state="0";

    public DataStashUnitStateLogPo(String unitProcId, String unitCode, String batchNo){
        this.unitProcId=unitProcId;
        this.unitCode=unitCode;
        this.batchNo=batchNo;
    }
    
    @Column(name="is_over")
    @ColumnPosition(12)
    private String isOver = "1"; // 0结束 1运行

}
